<template>
  <div class="LargeScreen">
    <el-form :model="form" :rules="rules" ref="form" label-width="100px">
      <el-form-item label="基数" prop="j_num">
        <el-input
          v-model="form.j_num"
          style="width: 300px"
          type="number"
        ></el-input>
      </el-form-item>
      <el-form-item label="增数" prop="z_num">
        <el-input
          v-model="form.z_num"
          style="width: 300px"
          type="number"
        ></el-input>
      </el-form-item>
      <el-form-item label="" prop="z_num">
        <el-button type="primary" @click="onSubmit('form')">保存</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { postAdminApigetUserNum, postAdminApiSetUserNum } from "@/api";
export default {
  data() {
    return {
      form: {
        j_num: "",
        z_num: "",
      },
      rules: {
        j_num: [{ required: true, message: "请输入基数", trigger: "blur" }],
        z_num: [{ required: true, message: "请输入增数", trigger: "blur" }],
      },
    };
  },
  mounted() {
    this.postAdminApigetUserNum();
  },
  methods: {
    postAdminApigetUserNum() {
      postAdminApigetUserNum().then((res) => {
        console.log("用户数-基础数据-------->", res);
        let data = res.data;
        this.form = {
          j_num: data.j_num,
          z_num: data.z_num,
        };
      });
    },
    onSubmit(e) {
      let that = this;
      this.$refs[e].validate((valid) => {
        if (valid) {
          that
            .$confirm("确定保存?", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            })
            .then(() => {
              postAdminApiSetUserNum(that.form).then((res) => {
                that.postAdminApigetUserNum();
                that.$message({
                  type: "success",
                  message: "保存成功!",
                });
              });
            })
            .catch(() => {
              this.$message({
                type: "info",
                message: "已取消保存",
              });
            });
        } else {
          return false;
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.LargeScreen {
  background: #fff;
  padding: 20px;
}
</style>